<template>
  <div class="app-container">
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item>
        <el-input v-model="userAddress" placeholder="用户地址" />
      </el-form-item>
      <el-button type="primary" icon="el-icon-search" @click="findUser()">用户地址查询</el-button>
    </el-form>
    <!-- banner列表 -->
    <el-table :data="list" stripe style="width: 100%">
      <el-table-column type="index" width="50" label="序号" />
      <el-table-column prop="userAddress" label="用户链上地址" />
      <el-table-column prop="userName" label="用户名" />
      <el-table-column prop="balance" label="用户账户余额" />
      <el-table-column prop="userAssetList" label="用户名下涉及资产集合" />
      <el-table-column prop="createTime" label="用户创建时间" />
    </el-table>
  </div>
</template>

<script>
import user from '@/api/user'

export default {
  data() {
    return {
      userAddress: '',
      list: []
    }
  },
  created() {
  },
  methods: {
    findUser() {
      user
        .findUser(this.userAddress)
        .then((response) => {
          const temp = response.data
          temp.userAssetList = this.arrayToString(temp.userAssetList)
          temp.createTime = this.timeFormatConversion(temp.createTime)
          const arr = []
          arr.push(temp)
          this.list = arr
          console.log(response)
        })
        .catch((error) => {
          console.log(error)
        })
    },
    // 将数组变成按照一定格式分隔的string
    arrayToString(array) {
      let res = ''
      for (let index = 0; index < array.length; index++) {
        res += array[index] + '\n'
      }
      console.log(res)
      return res
    },
    // 因为你时间传过来的是一个string，这里格式转换就是对字符串操作，如果你后端传过来格式是yyyy-mm-dd HH:MM:ss格式的就不用转换了
    timeFormatConversion(date) {
      return date.slice(0, 10) + ' ' + date.slice(11, 19)
    }
  }
}
</script>
